-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-18206][ML]Add instrumentation for MLP,NB,LDA,AFT,GLM,Isotonic,LiR #15671
Conversation
Test build #67700 has finished for PR 15671 at commit
|
Test build #67703 has finished for PR 15671 at commit
|
Test build #67704 has finished for PR 15671 at commit
|
Test build #67706 has finished for PR 15671 at commit
|
@@ -96,11 +96,13 @@ class DecisionTreeClassifier @Since("1.4.0") ( | |||
|
|||
val instr = Instrumentation.create(this, oldDataset) | |||
instr.logParams(params: _*) | |||
instr.logNumClasses(numClasses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are already logged inside of RandomForest.run
7c74241
to
05e2f4d
Compare
@sethah Thanks. I have revert those changes in Tree-Algos. |
Test build #67741 has finished for PR 15671 at commit
|
@jkbradley @yanboliang Could you please make a reivew? |
Minor: would you mind changing the title to "Add instrumentation logs to ML training algorithms". I initially thought this PR was adding them to the old MLlib API, so I think it's a bit more clear. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left mostly minor comments. Let's create a JIRA for other meta algorithms like CrossValidator
, TrainValidationSplit
, and OneVSRest
. Thanks for doing this!
@@ -234,8 +234,14 @@ class MultilayerPerceptronClassifier @Since("1.5.0") ( | |||
* @return Fitted model | |||
*/ | |||
override protected def train(dataset: Dataset[_]): MultilayerPerceptronClassificationModel = { | |||
val instr = Instrumentation.create(this, dataset) | |||
instr.logParams(params : _*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we are trying to log all params that are useful, but not params that could overload logs. Since MLP has a initialWeights
parameter that could potentially be very large, we should not include it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will update it here, and other algos which support a initalModel
@@ -216,7 +221,10 @@ class NaiveBayes @Since("1.5.0") ( | |||
|
|||
val pi = Vectors.dense(piArray) | |||
val theta = new DenseMatrix(numLabels, numFeatures, thetaArray, true) | |||
new NaiveBayesModel(uid, pi, theta).setOldLabels(labelArray) | |||
val model = new NaiveBayesModel(uid, pi, theta).setOldLabels(labelArray) | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty line
@@ -896,6 +896,10 @@ class LDA @Since("1.6.0") ( | |||
@Since("2.0.0") | |||
override def fit(dataset: Dataset[_]): LDAModel = { | |||
transformSchema(dataset.schema, logging = true) | |||
|
|||
val instr = Instrumentation.create(this, dataset) | |||
instr.logParams(params : _*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise here we probably should not log docConcentration
.
copyValues(newModel).setParent(this) | ||
|
||
val model = copyValues(newModel).setParent(this) | ||
instr.logSuccess(newModel) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: instr.logSuccess(model)
@@ -226,6 +226,10 @@ class AFTSurvivalRegression @Since("1.6.0") (@Since("1.6.0") override val uid: S | |||
val featuresStd = featuresSummarizer.variance.toArray.map(math.sqrt) | |||
val numFeatures = featuresStd.size | |||
|
|||
val instr = Instrumentation.create(this, dataset) | |||
instr.logParams(params : _*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should not log quantileProbabilities
? I am not familiar with this algorithm so I'm not sure if these can ever be too large.
@@ -276,6 +280,7 @@ class AFTSurvivalRegression @Since("1.6.0") (@Since("1.6.0") override val uid: S | |||
val intercept = parameters(1) | |||
val scale = math.exp(parameters(0)) | |||
val model = new AFTSurvivalRegressionModel(uid, coefficients, intercept, scale) | |||
instr.logSuccess(model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: move the logSuccess
call after the copyValues
. That way if we ever do something in logSuccess
like logging parameters of the model, the call will reflect the copied parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, would you mind changing the doc in Instrumentation.logSuccess
from:
"Logs the successful completion of the training session and the value of the learned model."
to
"Logs the successful completion of the training session."
Since we currently don't do anything other than log a string inside logSuccess
.
@@ -284,6 +288,7 @@ class GeneralizedLinearRegression @Since("2.0.0") (@Since("2.0.0") override val | |||
.setParent(this)) | |||
val trainingSummary = new GeneralizedLinearRegressionTrainingSummary(dataset, model, | |||
irlsModel.diagInvAtWA.toArray, irlsModel.numIterations, getSolver) | |||
instr.logSuccess(model) | |||
model.setSummary(trainingSummary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: move logSuccess
after setSummary
@@ -284,6 +288,7 @@ class GeneralizedLinearRegression @Since("2.0.0") (@Since("2.0.0") override val | |||
.setParent(this)) | |||
val trainingSummary = new GeneralizedLinearRegressionTrainingSummary(dataset, model, | |||
irlsModel.diagInvAtWA.toArray, irlsModel.numIterations, getSolver) | |||
instr.logSuccess(model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to log success if we enter the WeightedLeastSquares
branch above as well. Maybe we can refactor the code to use if else
instead of an if
with a return
. That way we only need to log success in one place.
@@ -392,6 +399,8 @@ class LinearRegression @Since("1.3.0") (@Since("1.3.0") override val uid: String | |||
model, | |||
Array(0D), | |||
objectiveHistory) | |||
|
|||
instr.logSuccess(model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor: move logSuccess after setSummary, here and elsewhere.
05e2f4d
to
df8734e
Compare
@sethah Thanks for your reviewing. I have made changes according to your comments. And I will create JIRAs for meta algos. |
Test build #67878 has finished for PR 15671 at commit
|
I just made a subtask for the algs covered here. Can you please link this PR to SPARK-18206 in the title instead of the umbrella task? |
So, if we consistently use For now, I think I lean towards manually selecting which params to log rather than logging all params. If we add more params later we will have to remember to add them to the logging. What are others' thoughts? Alternatively, we could use a filter on certain types of params - like |
Good point. I agree with you about logging selected Params only. |
@sethah @jkbradley OK, I will link this pr to the subtask and change algos which use |
df8734e
to
6d2d13f
Compare
Test build #67947 has finished for PR 15671 at commit
|
IMO, the way we're doing this logging right now is unsustainable. It requires too much manual work. We can leave this discussion for a different JIRA, but what we could do is modify the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments otherwise LGTM. Still, we definitely need to find a way to make this more sustainable.
return model.setSummary(trainingSummary) | ||
model.setSummary(trainingSummary) | ||
instr.logSuccess(model) | ||
return model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would you mind rewriting this if statement to:
val model = if (familyObj == Gaussian && linkObj == Identity) {
...
} else {
...
}
instr.logSuccess(model)
model
Then we can avoid the code duplication?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I will change this.
@@ -227,7 +227,8 @@ class AFTSurvivalRegression @Since("1.6.0") (@Since("1.6.0") override val uid: S | |||
val numFeatures = featuresStd.size | |||
|
|||
val instr = Instrumentation.create(this, dataset) | |||
instr.logParams(params : _*) | |||
instr.logParams(labelCol, featuresCol, censorCol, predictionCol, quantilesCol, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add aggregationDepth
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, Thanks
@@ -196,7 +196,8 @@ class LinearRegression @Since("1.3.0") (@Since("1.3.0") override val uid: String | |||
} | |||
|
|||
val instr = Instrumentation.create(this, dataset) | |||
instr.logParams(params : _*) | |||
instr.logParams(labelCol, featuresCol, weightCol, predictionCol, solver, tol, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add aggregationDepth
6d2d13f
to
e77bdc4
Compare
@sethah I have make changes according to the comments. Thanks for your reviewing. |
@sethah I agree that manually listing traceable params is prone to mistake. I think we can log all params expect some params which are labeled |
Test build #68039 has finished for PR 15671 at commit
|
I created SPARK-18253 to track it. We may have to get to it after 2.1 QA period. |
I don't want to truncate Param strings because it would create invalid JSON in case people want to try to catch and parse the logs. I like the idea of allowing exceptions and possibly adding unit tests to ensure the logs do not blow up. |
3e54b1f
to
c8693d8
Compare
@jkbradley Update according to your comments, including adding |
Test build #70901 has finished for PR 15671 at commit
|
Test build #71064 has finished for PR 15671 at commit
|
ping @jkbradley |
Thanks for the updates! For docConcentration and quantileProbabilities, I agree it could be problematic if these are too large. How about:
|
Test build #71285 has finished for PR 15671 at commit
|
@jkbradley Updated. Thanks for reviewing! |
re-ping @jkbradley |
LGTM pending one more run of the tests Jenkins test this please |
Test build #3537 has finished for PR 15671 at commit
|
Merging with master |
…,LiR ## What changes were proposed in this pull request? add instrumentation for MLP,NB,LDA,AFT,GLM,Isotonic,LiR ## How was this patch tested? local test in spark-shell Author: Zheng RuiFeng <[email protected]> Author: Ruifeng Zheng <[email protected]> Closes apache#15671 from zhengruifeng/lir_instr.
…,LiR ## What changes were proposed in this pull request? add instrumentation for MLP,NB,LDA,AFT,GLM,Isotonic,LiR ## How was this patch tested? local test in spark-shell Author: Zheng RuiFeng <[email protected]> Author: Ruifeng Zheng <[email protected]> Closes apache#15671 from zhengruifeng/lir_instr.
What changes were proposed in this pull request?
add instrumentation for MLP,NB,LDA,AFT,GLM,Isotonic,LiR
How was this patch tested?
local test in spark-shell